package com.example.springbootdatajpa.controller;

import com.example.springbootdatajpa.entities.DeptEmpDto;
import com.example.springbootdatajpa.repositories.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/department")
public class DepartmentController {
    @Autowired
    private DepartmentRepository departmentRepository;

    @GetMapping(value = "/leftJoin",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<DeptEmpDto>> leftJoin(){
        List<DeptEmpDto> deptEmpDtos = departmentRepository.fetchEmpDeptDataLeftJoin();
        return new ResponseEntity<>(deptEmpDtos, HttpStatus.OK);
    }

    @GetMapping(value = "/rightJoin",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<DeptEmpDto>> rightJoin(){
        List<DeptEmpDto> deptEmpDtos = departmentRepository.fetchEmpDeptDataRightJoin();
        return new ResponseEntity<>(deptEmpDtos, HttpStatus.OK);
    }

    @GetMapping(value = "/innerJoin",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<DeptEmpDto>> innerJoin(){
        List<DeptEmpDto> deptEmpDtos = departmentRepository.fetchEmpDeptDataInnerJoin();
        return new ResponseEntity<>(deptEmpDtos, HttpStatus.OK);
    }

    @GetMapping(value = "/crossJoin",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<DeptEmpDto>> crossJoin(){
        List<DeptEmpDto> deptEmpDtos = departmentRepository.fetchEmpDeptDataCrossJoin();
        return new ResponseEntity<>(deptEmpDtos, HttpStatus.OK);
    }
}
